package com.treasure.service.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.treasure.service.domain.AppVerion;
import com.treasure.service.domain.AppVerionExample;
import com.treasure.service.dto.AppVersionCheckResult;
import com.treasure.service.mapper.AppVerionMapper;
import com.treasure.service.user.service.AppVersionService;

@Service("appVersionService")
public class AppVersionServiceImpl implements AppVersionService {
	@Autowired
	private AppVerionMapper appVerionMapper;
	
	@Override
	public AppVersionCheckResult checkUpdate(String osName, int versionCode) {
		AppVerionExample appVerionExample = new AppVerionExample();
		appVerionExample.createCriteria().andOsNameEqualTo(osName)
										 .andVersionTypeEqualTo(2);
		List<AppVerion> list = appVerionMapper.selectByExample(appVerionExample);
		AppVersionCheckResult result = new AppVersionCheckResult();
		result.setHasNewVersion("N");
		if(list!=null && list.size()>0) {
			AppVerion appVersion = list.get(0);
			if(versionCode<appVersion.getVersionCode()) {
				result.setHasNewVersion("Y");//是否需要更新
				result.setIsForce(appVersion.getIsForce());//强制更新
				result.setUpdateDesc(appVersion.getUpdateDesc());//更新描述
				result.setDownloadUrl(appVersion.getDownloadUrl());//新版下载地址
				result.setVersionName(appVersion.getVersionName());
			}
		}
		return result;
	}

}
